using System;
using IMath;

namespace MathLib
{
    /// <summary>
    /// 数学计算类，实现IMathOperation接口
    /// </summary>
    public class MathCalculator : IMathOperation
    {
        /// <summary>
        /// 执行加法运算
        /// </summary>
        /// <param name="a">第一个操作数</param>
        /// <param name="b">第二个操作数</param>
        /// <returns>两个数的和</returns>
        public double Add(double a, double b)
        {
            return a + b;
        }
        
        /// <summary>
        /// 执行减法运算
        /// </summary>
        /// <param name="a">被减数</param>
        /// <param name="b">减数</param>
        /// <returns>两个数的差</returns>
        public double Subtract(double a, double b)
        {
            return a - b;
        }
        
        /// <summary>
        /// 执行乘法运算
        /// </summary>
        /// <param name="a">第一个因数</param>
        /// <param name="b">第二个因数</param>
        /// <returns>两个数的积</returns>
        public double Multiply(double a, double b)
        {
            return a * b;
        }
        
        /// <summary>
        /// 执行除法运算
        /// </summary>
        /// <param name="a">被除数</param>
        /// <param name="b">除数</param>
        /// <returns>两个数的商</returns>
        /// <exception cref="DivideByZeroException">当除数为零时抛出</exception>
        public double Divide(double a, double b)
        {
            if (b == 0)
            {
                throw new DivideByZeroException("除数不能为零");
            }
            return a / b;
        }
    }
}